package com.zyg.controller;

import com.zyg.model.Result;
import com.zyg.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

/**
 * @author: 牛二
 * @date: 2020/8/20 17:56
 * @email: 550354312@qq.com
 * @project: zyg_project_demo
 * @describe:
 */
@RestController
public class SysFileController {

    @Autowired
    private FileService fileService;

    /**
     * 文件上传
     * @param multipartFile 文件
     * @return
     */
    @PostMapping("/va/file/upload")
    public Result saveFile(MultipartFile multipartFile){
        return fileService.saveFile(multipartFile);
    }

    /**
     * 文件的下载
     * @param id 附件id
     * @return
     */
    @GetMapping("/va/file/download/{id}")
    public void getFileById(@PathVariable String id, HttpServletResponse response){
        fileService.getFileById(id,response);
    }

    /**
     * 文件类型转换
     * @param id 附件id
     * @return
     */
    @GetMapping("/va/file/conversion/{id}")
    public void getFileConversion(@PathVariable String id, HttpServletResponse response){
        fileService.getFileConversion(id,response);
    }

}
